package org.wattdepot.cli.command;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

/**
 * Test for Chart Power.
 * 
 * @author Remy Baumgarten
 * @author Kevin Chiogioji
 * 
 */
public class TestChartPower {

  private static final String filen = "kahe-september-energy.html";

  /**
   * Test for ChartPower.
   * 
   * @throws Exception -
   */
  @Test
  public void checkOutput() throws Exception {
    System.out.println("ChartPower: Testing output...");
    ChartPower power = new ChartPower();
    List<String> args = new ArrayList<String>();
    args.add("generated");
    args.add("SIM_KAHE_2");
    args.add("2009-10-31");
    args.add("2009-11-01");
    args.add("60");
    args.add(filen);
    assertEquals("Checking to see if output is correct", power.doCommand(args), "HTML Generated");
  }

  /**
   * Test for File Write.
   * 
   * @throws Exception -
   */
  @Test
  public void checkFileWrite() throws Exception {
    System.out.println("ChartPower: Testing to see if I can write a file...");
    ChartPower power = new ChartPower();
    List<String> args = new ArrayList<String>();
    args.add("generated");
    args.add("SIM_KAHE_2");
    args.add("2009-10-31");
    args.add("2009-11-01");
    args.add("60");
    args.add(filen);
    power.doCommand(args);
    File file = new File(filen);
    assertTrue("Checking if file was written", file.exists());
  }

  /**
   * Checks Invalid Format Handling.
   * 
   * @throws Exception -
   */
  @Test
  public void inputValidation() throws Exception {
    System.out.println("ChartPower: Testing Input Validation...");
    ChartPower power = new ChartPower();
    List<String> args = new ArrayList<String>();
    args.add("generated");
    args.add("SIM_KAHE_2");
    args.add("2009-10-311111111");
    args.add("2009-11-0111111111");
    args.add("60");
    args.add(filen);
    assertEquals("Checking to see if command handling is correct", power.doCommand(args),
        "Invalid TimeStamp Formatting");
  }
}
